#pragma once

template <typename T> class PStack
{
public:
	PStack():_begin(0),_length(0),_capacity(0) {}
	~PStack()
	{
		delete[] _begin;
	}
	inline void clear()
	{
		_length=0;
	}
	inline void push(T t)
	{
		if(_length>=_capacity)
		{
			_capacity=(_length+1)*2;
			T * p=new T[_capacity];
			for(int i=0;i<_length;++i) p[i]=_begin[i];
			delete[] _begin;
			_begin=p;
		}
		_begin[_length]=t;
		++_length;
	}
	inline bool pop(T &t)
	{
		if(_length)
		{
			t=_begin[_length-1];
			--_length;
			return true;
		}
		return false;
	}
protected:
	T * _begin;
	int _length;
	int _capacity;
};